<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="/pages/common/taglibs.jsp" %>

<jsp:useBean id="JSONRPCBridge" scope="session" class="org.jabsorb.JSONRPCBridge" />
<jsp:useBean id="jabsorbService" scope="session" class="com.ivo.jabsorb.JabsorbService" />

<%
	JSONRPCBridge.registerObject("jabsorbService", jabsorbService);
%>

<html>
  <head>    
    <title>[${tmpl.templateName }] 表单样式预览</title>
    <%@ include file="/pages/common/meta.jsp" %>
	<!-- import EXTJS -->
	<%@ include file="/pages/common/extjs.jsp" %>
	<!-- import jQuery -->
	<%@ include file="/pages/common/jquery-base.jsp" %>

	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.tabs.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.button.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.datepicker.js"></script>
	
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.center.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.numeric.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.numberformatter-1.1.2.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.form-2.43.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ux.formvalidate.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.tablesorter.js"></script>
	
	<link rel="stylesheet" href="${ctx }/jQuery/css/table/blue/style.css" type="text/css" media="print, projection, screen" /> 
	<link type="text/css" href="${ctx }/jQuery/demos.css" rel="stylesheet" />
	
	<!-- import jsonrpc -->
	<script type="text/javascript" src="${ctx }/scripts/jsonrpc.js"></script>
	<!-- import report style -->
	<script type="text/javascript" src="${ctx }/pages/pdm/BomReport_Preview.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/FurSelectionWindow_Preview.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/GpReport_Preview.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/MaReport_Preview.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/FurDetails_Preview.js"></script>

	<link rel="stylesheet" type="text/css" href="${ctx }/styles/ext-button.css" rel="stylesheet" />
	
	<style type="text/css">
		.warning{
			border:1px  solid red;
		}
		.cls_validator_error {
			border: 1px solid #F20101;
			background: #FFF39C;
		}		
	</style>
	<!-- import css for tag -->
	<style type="text/css">
		.css_singleLine_tag{
			height: 26px;
			width: 89.7%;
			background: #E4F2FB;
			border-bottom: 1px solid #64B8E4;
		}
		.css_singleLine_tag ul{
			list-style: none;
			margin: 2px 10px;
			padding: 0;
			position: absolute;
		}
		.css_singleLine_tag ul li{
			float: left;
			background: #fff;
			line-height: 22px;
			display: block;
			cursor: pointer;
			width: auto;
			text-align: center;
			padding: 0em 1em;
			color: #E17009;
			font-weight: bold;
			border-top:1px solid #64B8E4;
			border-left:1px solid #64B8E4;
			border-right:1px solid #64B8E4;
			border-bottom:1px solid #64B8E4;
		}
	</style>
	
	<script type="text/javascript">
		window.basePath = "${ctx }";
		
		$(function(){
			$("#evaluation_tabs").tabs();
			$("#dcc_link_tabs").tabs();
			$("#attachment_tabs").tabs();
			$("#conclusion_tabs").tabs();
			
			$.ajax({
				type: "post",
				cache: "false",
				url: "/pdm/page/previewSheet.htm?tmpl_fk=${tmpl.templateId }",
				dataType: "json",
				contentType: "application/json; charset=utf-8",
				timeout: 20000,
				error: function(){
				    $("#evaluation_tab_1").html("<font color=red>请求失败</font>");
				    $("#preloader").hide();
				},
				success: function(json){
				    $("#evaluation_tab_1").html(json[0].data);
				    $("#preloader").hide();
				    
				    var divStyle = json[0].style;
				    
				    if(divStyle.substr(0,1)==0){
				    	$("#conclusion_tabs").hide();
				    }
				    
				    if(divStyle.substr(1,1)==0){
				    	$("#dcc_link_tabs").hide();
				    }
				    
				    if(divStyle.substr(2,1)==1){
				    	$("#conclusion_tabs").show();
				    	$("#conclusion table tr td label").each(function(){
				    		$(this).empty();
				    		if($(this).attr("for")=="available")
				    		{
				    			$(this).append("Pass");
				    		}
				    		else if($(this).attr("for")=="unavailable")
				    		{
				    			$(this).append("Fail");
				    		}
				    		else if($(this).attr("for")=="conditional")
				    		{
				    			$(this).append("Conditional Pass");
				    		}
				    	});
				    }
				    //$("#conclusion").buttonset();
				    
				    if(hasReportType("DT024"))
					{
						var objectName = $("#btn_furSelection").parent().prev().find("input").attr("id");
						var objectValue = $("#btn_furSelection").parent().prev().find("input").attr("value");
						var win = null;
						createFollowUpButton(win, objectName, objectValue, "true", window.basePath);
					}
					else if(hasReportType("DT025"))
					{
						var objectName = $("#div_selected_material_grid").parent().parent().prev().find("input").attr("id");
						var objectValue = $("#div_selected_material_grid").parent().parent().prev().find("input").attr("value");
						//var objectValue = $("#hidden_BoMParam").attr("value");
						createBoMReport("", objectName, objectValue, "true", "");
					}
					else if(hasReportType("DT026"))
					{
						var objectName = $("#btn_dc_query").parent().next().find("input").attr("id");
						
						createDcReport("", objectName, "", "true", "");
					}
					else if(hasReportType("DT027"))
					{
						var objectName = $("#div_gp_param_grid").parent().parent().prev().find("input").attr("id");
						var objectValue = $("#div_gp_param_grid").parent().parent().prev().find("input").attr("value");
						
						createGpReport("", objectName, objectValue, "true", "");
					}
					else if(hasReportType("DT028"))
					{
						var objectName = $("#btn_select_fur").parent().prev().find("input").attr("id");
						var objectValue = $("#btn_select_fur").parent().prev().find("input").attr("value");
						
						var win = null;
						createFurDelay(win, objectName, objectValue, "true", "");
					}
					else if(hasReportType("DT036"))
					{
						var objectName = $("#div_ma_param_grid").parent().parent().prev().find("input").attr("id");
						var objectValue = $("#div_ma_param_grid").parent().parent().prev().find("input").attr("value");
						
						createMaReport("", objectName, objectValue, "true", "");
					}
				}
			});
		});
	</script>
	
	<script>
		Ext.BLANK_IMAGE_URL = './ext-3.2/resources/images/default/s.gif';
		Ext.onReady(function(){
			var dccLink = new DccLinkGrid({id: 'dccLinkGrid'});
			dccLink.render("dcc_link_tab_1");
			
			var attachmentGrid = new AttachmentGrid({id: "attachmentGrid"});
			attachmentGrid.render("attachment_tab_1");
			
		});
	</script>
	
	<script>
	/****************************************************
	 * @class DccLinkGrid
	 * @extends Ext.grid.GridPanel
	 ***************************************************/
	DccLinkGrid = Ext.extend(Ext.grid.GridPanel,{
		cm: null,
		store: null,
		condition: null,
		documentMultiSelectionWindow: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			this.cm = new Ext.grid.ColumnModel([
				{ dataIndex: 'attachment_Id', hidden:true},
				new Ext.grid.RowNumberer(),
				{ dataIndex: 'ref', width: 40},
				{ dataIndex: 'documentName', width: 100, sortable:false},
				{ dataIndex: 'fileName', width: 350, sortable:false}
			]);
			
			this.store = new Ext.data.Store({
			    proxy: new Ext.data.HttpProxy({
			    	method: 'POST',
					url: ''
				}),
		        reader: new Ext.data.JsonReader({
					 totalProperty: 'totalProperty',
					 root: 'root',
					 id: 'attachment_ID'
				},[
					{name: 'attachment_ID'},
					{name: 'ref'},
					{name: 'attachmentBase'},
					{name: 'documentName'},
					{name: 'fileName'},
					{name: 'mark'}
				])
			});
			
			DccLinkGrid.superclass.constructor.call(this, {
				store: this.store,
				cm: this.cm,
				anchor: '98%',
				autoHeight: true,
				viewConfig: {forceFit: true},
				tbar:[{
					id: 'btn_ext_add_doc',
					text: "添加",
					iconCls: 'add',
					handler:function(){
						
					}
				}]
			});
		}
	});			
	/****************************************************
	 * @class AttachmentGrid
	 * @extends Ext.grid.GridPanel
	 ***************************************************/
	AttachmentGrid = Ext.extend(Ext.grid.GridPanel,{
		store: null,
		cm: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			this.cm = new Ext.grid.ColumnModel([
				{dataIndex: 'attachment_ID', hidden:true},
				new Ext.grid.RowNumberer(),
				{header: " ", width:35 },
	            {header: "名称", width:500, dataIndex: 'fileName'},
	            {header: "大小", width:80, dataIndex: 'size'},
	            {header: "上传人员", width:160, dataIndex: 'ownerName'}
			]);
			
			this.store = new Ext.data.Store({
			    proxy: new Ext.data.HttpProxy({
			    	method: 'POST',  
				 	url: ''
				}),
				reader: new Ext.data.JsonReader({
					totalProperty: 'totalProperty',
					root: 'root',
					id: 'attachment_ID'
				},[
					{name: 'attachment_ID'},
					{name: 'fileName'},
					{name: 'size'},
					{name: 'ownerName'},
					{name: 'owner_FK'}
				])
			});
			
			AttachmentGrid.superclass.constructor.call(this, {
				store: this.store,
		        cm: this.cm,
		        autoHeight: true,
		        anchor: '98%',
		        viewConfig: {forceFit: true},
		        tbar:[{
		        	id: 'btn_ext_add_attach',
					text: "增加",
					tooltip: "增加相关的附件",
					iconCls: 'add',
					handler: function(){
					
					}
				},{
					id: 'btn_ext_del_attach',
					text: "删除",
					tooltip: "删除相关的附件",
					iconCls: 'delete',
					scope: this,
					handler: function(){
					
					}
				}]
			});
		}
	});
	
/********************************************************************************/
	function hasReportType(data_type){
		var tmpl_id = "${tmpl.templateId }";
		var jsonrpc = new JSONRpcClient("/pdm/JSON-RPC");
		try{
			var info = jsonrpc.jabsorbService.hasReportType(tmpl_id,data_type);
		}catch(e){
			alert(e);
		}
		return info;
	}
	
	</script>
	<script type="text/javascript">
	
/** =======================================================
 *  Create Follow Up Button
 ** ==================================================== */	
	function createFollowUpButton(win, name, value, bAuth, basePath){
		var button = new Ext.Button({
			text: "选择...",
			scope: this,
			hidden: (bAuth=="false"),
			handler: function() {
				if(Ext.isEmpty(win)){
					var furSelectionGrid = new FURSelectionGridPanel({txtfld: name});
					win = new FURSelectionWindow({id: "ext_selectionWin", title: "FUR选择窗口", furSelectionGrid: furSelectionGrid, txtfld: name});
				}
				win.show();
			}
		});
		
		var panel = new Ext.Panel({
				id: "ext_furInfo",
				title: "申请单信息",
				height: 480,
				autoDestroy: true,
				html: '<iframe src="'+basePath+'images/app/nothingfound.png" width="100%" height="100%" frameborder=1 scrolling=auto></iframe>'
			});
		
		panel.render("div_FurInfo");
		button.render("btn_furSelection");
	}
/** =======================================================
 *  Create BOM Report
 ** ==================================================== */
	function createBoMReport(win, name, value, bAuth, basePath){
		
		var grid = new BomReportGridPanel({id: 'gp_BomReport', title: "相关BOM信息"});
		var selectedMaterial = new SelectedMaterialGrid({id: 'gp_SelectedMaterial', btn_auth: bAuth, hidden_BoMParam: name});
		
		grid.render("div_bom_grid");
		selectedMaterial.render("div_selected_material_grid");
		
	}
/** =======================================================
 *  Create DC Report
 ** ==================================================== */
	function createDcReport(win, name, value, bAuth, basePath){
		
		$("#minDateOfECR").datepicker();
		$('#minDateOfECR').datepicker('option', {dateFormat: "yy-mm-dd"});
		
		$("#maxDateOfECR").datepicker();
		$('#maxDateOfECR').datepicker('option', {dateFormat: "yy-mm-dd"});
		
		var paramJson = $("#"+name).attr("value");
		var param = "";
		$("#dc_result_table").tablesorter({widgets: ['zebra']});
		
		if(bAuth=="false") $("#btn_dc_query").hide();
		
		$("#btn_dc_query").click(function() {});		
	}
/** =======================================================
 *  Create GP Report
 ** ==================================================== */
	function createGpReport(win, name, value, bAuth, basePath){
		
		var grid = new GpReportGridPanel({id: 'gp_gpReport', title: "相关GP信息"});
		var paramGrid = new GpParamGrid({id: 'gp_GpParam', btn_auth: bAuth, hidden_GpParam: name});
		
		paramGrid.render("div_gp_param_grid");
		grid.render("div_gp_info_grid");
		
		if(value == "") value="[]";
	}
/** =======================================================
 *  Create Ma Report
 ** ==================================================== */
	function createMaReport(win, name, value, bAuth, basePath){
		
		var grid = new MaReportGridPanel({id: 'gp_MaReport', title: "相关物料承认信息"});
		var paramGrid = new MaParamGrid({id: 'gp_MaParam', btn_auth: bAuth, hidden_MaParam: name});
		
		paramGrid.render("div_ma_param_grid");
		grid.render("div_ma_info_grid");
		
		if(value == "") value="[]";

	}
	
/** =======================================================
 *  Create FUR Delay Details
 ** ==================================================== */
	function createFurDelay(win, name, value, bAuth, basePath){
		
		var button = new Ext.Button({
			text: "选择...",
			scope: this,
			hidden: (bAuth=='false'),
			handler: function() {
				if(Ext.isEmpty(win)){
					var furListGridPanel = new FurListGridPanel();
					win = new FurListWindow({id: "win_FurList", title: "FUR选择窗口", furListGrid: furListGridPanel, keyName: name});
				}
				win.show();
			}
		});
		
		button.render("btn_select_fur");
		
		$("#pdm_div_overDue").empty();
		$("#pdm_div_overDue").append("逾期数量：(  <a href=\"javascript:openDelayItems('')\"><font color=red>0</font></a>  )项");

	}
	
	function openDelayItems(v)
	{
		if(v==""){
			Ext.Msg.alert("提示","没有逾期项目");
		}else{
			var gp = Ext.getCmp("pm_furDetails");
			if(Ext.isEmpty(gp)) gp = new FurDetailsGridPanel({id: 'pm_furDetails'});
			
			var w = Ext.getCmp("win_pm_furDetails");
			if(Ext.isEmpty(w)) w = new FurDetailsWindow({id: 'win_pm_furDetails',title: "逾期事项", furDetailsGrid: gp});
			w.show();
		}
	}
	</script>
	
  </head>
  
  <body>
  	<div id="toolbar_ExtJs"></div>
  
  	<div id="base" align="center">
		<div id="evaluation_tabs" style="width:92%">
			<ul>
				<li><a href="#evaluation_tab_1">重要信息</a></li>
			</ul>
			<div id="evaluation_tab_1">
				<div id="preloader"><img src="<%=request.getContextPath()%>/images/pdm/preloading.gif" /></div>
			</div>
		</div>
		<div id="conclusion_tabs" style="width:92%">
			<ul>
				<li><a href="#conclusion_tab_1">结论(NA)</a></li>
			</ul>
			<div id="conclusion_tab_1">
				<div id="conclusion" align="left">
					<table style="width:95%">
						<tr>
							<td style="width:50px;"><input type="radio" id="available" name="conclusion" value="available" /><label for="available">可行</label></td>
							<td style="width:63px;"><input type="radio" id="unavailable" name="conclusion" value="unavailable" /><label for="unavailable">不可行</label></td>
							<td style="width:110px;"><input type="radio" id="conditional" name="conclusion" value="conditional" /><label for="conditional">有条件的</label></td>
							<td>&nbsp;&nbsp;<input type="text" id="reason" name="reason" style="width:85%;" value="" validator="type:string;maxLength:300;" /></td>
						</tr>
					</table>
				</div>
			</div>
		</div>
		<div id="dcc_link_tabs" style="width:92%">
			<ul>
				<li><a href="#dcc_link_tab_1">DCC Link</a></li>
			</ul>
			<div id="dcc_link_tab_1" align=left>
			</div>
		</div>
		<div id="attachment_tabs" style="width:92%">
			<ul>
				<li><a href="#attachment_tab_1">Attachment Link</a></li>
			</ul>
			<div id="attachment_tab_1" align=left></div>
		</div>
	</div>

  </body>
</html>
